import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from "@/layout"
import MODULES_ROUTER from './model/modules'
import myRouter from "./model/my"

Vue.use(VueRouter)
const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/login'),
    // meta: { title: '登录', icon: 'dashboard' }
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: '首页',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  myRouter,
  MODULES_ROUTER
];

const createRouter = () => new VueRouter({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
